package com.easytake.emotioncat.dto;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
@Schema(title = "分页对象")
public class PageResult<T> implements Serializable {
    @Schema(title = "当前页码")
    private long pageNo;

    @Schema(title = "每页数量")
    private long pageSize;

    @Schema(title = "结果总数量")
    private long totalSize;

    @Schema(title = "结果总页码")
    private long totalPage;

    @Schema(title = "结果集合")
    private List<T> results = new ArrayList<>();

    public PageResult(IPage<T> page) {
        this.pageNo = page.getCurrent();
        this.pageSize = page.getSize();
        this.totalPage = page.getPages();
        this.totalSize = page.getTotal();
        this.results = page.getRecords();
    }

}
